import time
f=open('m1_sorted.txt','r')
f2=open('m2_reverse.txt','r')
f3=open('m3_shuffle.txt','r')
arr=[]
def bubble(arr):
    n=len(arr)
    sw=False
    for i in range(n-1):
        for j in range(n-i-1):
            if arr[j]>arr[j+1]:
                arr[j],arr[j+1]=arr[j+1],arr[j]
                sw=True
        if sw==False:
            return
    return
for t in range(3):
    for i in range(4999):
        x=f.readline()
        arr.append(int(x[0:len(x)-1]))
    arr.append(int(f.readline()))
    start=time.time()
    bubble(arr)
    finish=time.time()
    print((finish-start)*1000)
    if t==0:
        f=f2
        arr=[]
    else:
        f=f3
        arr=[]
